﻿Imports System.Data.OleDb
Public Class routedetails
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If IsPostBack = False Then
            If Request.Params("q") = "" Then Response.Redirect("route.aspx")

            getComments(Request.Params("q"))



        End If



    End Sub



    Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionStringx").ConnectionString)
        Dim SqlString As String = "Insert into comments (title, comment, poster, comment_of_FK) Values (@f1, @f2, @f3, @f4)"
        'Dim SqlString As String = "INSERT into users (username, [password]) VALUES ('a','b')"     channel, @f9
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", txtCommentTitle.Text)
        cmd.Parameters.AddWithValue("@f2", txtComment.Text)
        cmd.Parameters.AddWithValue("@f3", 7)
        cmd.Parameters.AddWithValue("@f4", Request.Params("q"))
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        oleDbConn.Close()
        txtCommentTitle.Text = ""
        txtComment.Text = ""
        getComments(Request.Params("q"))
    End Sub

    Protected Sub AjaxFileUpload1_OnUploadComplete(ByVal sender As Object, ByVal fileInfo As AjaxControlToolkit.AjaxFileUploadEventArgs) Handles AjaxFileUpload1.UploadComplete

        AjaxFileUpload1.SaveAs(Request.MapPath("uploads") & "/" & fileInfo.FileName)
        'here needs to run save to db code

    End Sub

    Public Function getComments(ByVal routeId As Integer)

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionStringx").ConnectionString)
        Dim SqlString As String = "SELECT * FROM comments WHERE comment_of_FK = @f1"
        'Dim SqlString As String = "INSERT into users (username, [password]) VALUES ('a','b')"     channel, @f9
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", routeId)
        oleDbConn.Open()
        Dim DataReader = cmd.ExecuteReader
        GridView1.DataSource = DataReader
        GridView1.DataBind()
        cmd.Dispose()
        oleDbConn.Close()
        Return True
    End Function

    '  Public Function Rating1_Changed()
    '      txtTag.Text = Rating1.CurrentRating
    '      Return True
  '  End Function

End Class